package com.example.viewpageapplication.fragment;

import android.content.Context;
import android.os.Bundle;

import androidx.constraintlayout.utils.widget.ImageFilterView;
import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import com.example.viewpageapplication.R;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link DynamicFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class DynamicFragment extends Fragment {

    public static DynamicFragment newInstance(int postion,int image_id,int count) {
        DynamicFragment dynamicFragment = new DynamicFragment();
        Bundle args = new Bundle();
        args.putInt("postion",postion);
        args.putInt("image_id",image_id);
        args.putInt("count",count);
        dynamicFragment.setArguments(args);
        return dynamicFragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_dynamic,container,false);
        Context context = getContext();
        Bundle arguments = getArguments();
        int count  = arguments.getInt("count",0);
        int postion = arguments.getInt("postion",0);
        int image_id = arguments.getInt("image_id",0);


        ImageFilterView view1 = view.findViewById(R.id.ifv_itemfg);
        RadioGroup radioGroup = view.findViewById(R.id.rgp_startfg);
        Button button = view.findViewById(R.id.btn_startfg);
        view1.setImageResource(image_id);

        for (int i = 0; i < count; i++) {
            RadioButton radioButton = new RadioButton(context);
            radioButton.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT
            ));
            radioButton.setPadding(10,10,10,10);
            radioGroup.addView(radioButton);
        }

        ((RadioButton)radioGroup.getChildAt(postion)).setChecked(true);

        if(postion == count-1){
            button.setVisibility(View.VISIBLE);
            button.setText("欢迎开启美好生活");
        }


        return view;
    }
}